home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Virtual Graphics Kernel Macintosh Real Graphics Interface
- * (rgmac.c)
- *
- * National Center for Supercomputing Applications
- * by Gaige B. Paulsen
- *
- * This file contains the macintosh real screen calls for the NCSA
- * Virtual Graphics Kernel.
- *
- * Following are the Per Device calls:
- *
- * MacRGbell() - Ring window's bell
- * MacRGhidecur() - Turn the graphics cursor off in window
- * MacRGshowcur() - Turn the graphics cursor on in window
- * MacRGpencolor( r,g,b) - Set the pencolor to 16b R,G,B
- * MacRGraster( p,x1,y1,x2,y2,wid)- Plot raster in rect @(x1,y1,x2,y2) with wid @ p
- * MacRGline( x1,y2,x2,y2) - Draw a line (x1,y1) - (x2,y2)
- * MacRGlinestyle( n) - Set line style to n
- * MacRGpoint( x1,y1) - Plot a point at (x1,y1)
- * MacRGfill( x1,y1,x2,y2) - Fill bounded rectange (x1,y1)-(x2,y2) with pencolor
- * MacRGcopy( x1,y1,x2,y2,x3,y3,x4,y4)-
- * MacRGmap( offset,count,data) -
- *
- *
- * WARNING, WARNING!
- * Gaige has this cute idea about how to do "subwindows" of real windows by shifting
- * the window number by 4 bits (MAC_WINDOW_SHIFT). Then, the remainder is the
- * sub-window number. It will probably work, but you MUST keep the shifted and
- * non-shifted numbers straight. For example, MacRGdestroy() and MacRGremove() take
- * different uses of the window number right now.
- *
- *
- * Macintosh only Routines:
- *
- * Version Date Notes
- * ------- ------ ---------------------------------------------------
- * 0.5 880912 Initial Coding -GBP
- * 1.0 890216 Minor fixes for 1.0 - TKK
- */
-
- #define __ALLNU__
- #include <Events.h>
- #include <Controls.h>
- #include <OSUtils.h>
- #include <Dialogs.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Palette.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include <Scrap.h>
-
- #define RG_MASTER
-
- #include <stdio.h>
- #include <string.h>
-
- #include "RGrout.h"
- #include "mpw.h"
- #include "configrec.h"
- #include "maclook.h"
- #include "vdevice.h"
- #include "rr.h"
- #include "vr.h"
- #include "netevent.h"
-
- #define MAX_MAC_RGS 8
- #define MAX_MAC_SUB 16
- #define MAC_WINDOW_SHIFT 4 /* Bits shifted */
- #define MAC_SUB_MASK 0xf /* Bits maksed */
-
- extern unsigned char tempspot[];
-
- typedef struct MacWindow {
- VDevice vdev; /* virtual device to draw in, has its own colors */
- WindowPtr window; /* My Window (0L if not in use ) */
- PaletteHandle palette; /* My Palette */
- char title[256]; /* Title string */
-
-
- Point size; /* My height and width */
- Rect subs[MAX_MAC_SUB];/* Rectangles of my subwindows [0,0,0,0] if not in use */
- } MacWindow;
-
- MacWindow *MacRGs;
-
- int MacRGbell(), MacRGhidecur(), MacRGshowcur(), MacRGpencolor(), MacRGraster(), MacRGline(),
- MacRGlinestyle(), MacRGpoint(), MacRGfill(), MacRGmap();
-
- int RGwn=0; /* Window number in use */
- int RGsub=0; /* Sub-Window Number in use */
-
- void MacRGinit
- (
- void
- )
- {
- int i;
-
- MacRGs= (MacWindow *)NewPtr( MAX_MAC_RGS * sizeof(MacWindow));
- for (i=0;i<MAX_MAC_RGS;i++)
- MacRGs[i].window=NULL;
- }
-
- /************************************************************
- * MacRGnewwindow( name, x1, y1, x2, y2) - *
- * make a new subwindow to wn *
- ************************************************************/
-
- int MacRGnewwindow
- (
- char *name,
- int x1,
- int y1,
- int x2,
- int y2
- )
- {
- int w,i ;
- extern int RScolor;
- Rect wDims;
- register char *p;
- RGBColor curcol;
-
- p = (char *)NewPtr(1000 + (x2-x1+5) *(y2-y1+5));
- if (!p) {
- #ifdef MPW
- OtherError("Raster window create error.","Not enough memory to open.");
- #endif
- return(-1);
- }
- else
- DisposPtr(p);
-
- for (w=0; w<MAX_MAC_RGS && MacRGs[w].window; w++);
-
- if (w>= MAX_MAC_RGS)
- return( -1);
-
- if ((x2 - x1) & 1) /* odd width, must be even */
- x2++;
-
- SetRect( &wDims, x1+40, y1+40, x2+40, y2+40);
-
- strcpy( MacRGs[w].title, name); /* Copy of the name */
-
- if (!RScolor) /* Borrow from RS */
- return(-1);
- /* MacRGs[w].window=newwindow(0L, &wDims, name, TRUE, 4, -1L, TRUE, (long) w); */
- else {
- int i;
-
- MacRGs[w].window=newcwindow(NULL, &wDims, name, TRUE, 4, (WindowPtr) -1L,
- TRUE, (long) w);
-
-
- MacRGs[w].vdev.bp = (char *)NewPtr( (x2-x1+5) *(y2-y1+5));
- if (!MacRGs[w].vdev.bp) putln("Window has no bitmap...");
- else {
- SetRect(&MacRGs[w].vdev.bounds, 0,0, x2-x1, y2-y1);
- InitVDevice(&MacRGs[w].vdev); /* get vdevice going */
-
-
- MacRGs[w].palette = NewPalette( 256, NULL, pmTolerant, 0);
-
- for (i=0; i<256; i++) { /* load with grey-scale */
- curcol.red = i<<8;
- curcol.green = i<<8;
- curcol.blue = i<<8;
- SetEntryColor( MacRGs[w].palette, i, &curcol);
- }
-
- SetPalette( MacRGs[w].window, MacRGs[w].palette, TRUE);
- ActivatePalette( MacRGs[w].window);
-
- ColorVDevice(&MacRGs[w].vdev,MacRGs[w].palette);
- }
- }
-
-
- if (!MacRGs[w].window) {
- putln("Couldn't open Real Window");
- return(-2);
- }
-
- MacRGs[w].size.h = x2-x1;
- MacRGs[w].size.v = y2-y1;
- for (i=0; i<MAX_MAC_SUB; i++)
- SetRect( &MacRGs[w].subs[i], 0,0,0,0); /* Reset the subs */
- RGwn = w;
- RGsub= 0;
- return (w << MAC_WINDOW_SHIFT);
- }
-
- /****************************************
- * MacRGsubwindow(wn) - *
- * make a new subwindow to wn *
- ****************************************/
-
- int MacRGsubwindow
- (
- int wn
- )
- {
- return (wn);
- }
-
- /****************************************
- * MacRGsetwindow(wn) - *
- * set the drawing window to wn *
- ****************************************/
-
- void MacRGsetwindow
- (
- int wn
- )
- {
- int w = wn >> MAC_WINDOW_SHIFT;
-
- if (!MacRGs[w].window)
- return;
-
- SetPort( MacRGs[w].window);
- RGwn = w;
- RGsub= wn & MAC_SUB_MASK;
-
- /* Optionally set the clip region */
- }
-
- /****************************************
- * MacRGdestroy(wn) - *
- * destroy window wn *
- ****************************************/
- void MacRGdestroy
- (
- int wn
- )
- {
-
- sprintf(tempspot,"destroy: %d", wn); putln(tempspot);
- if (!MacRGs[wn].window)
- return;
-
- VRdestroy((union arg *) &MacRGs[wn].title);
- }
-
- /****************************************
- * MacRGremove(wn) - *
- * destroy window wn *
- ****************************************/
- void MacRGremove
- (
- int wn
- )
- {
- CGrafPtr cgp;
- int w = wn>> MAC_WINDOW_SHIFT;
-
- if (!MacRGs[w].window)
- return;
-
- TrashVDevice(&MacRGs[w].vdev);
-
- if (MacRGs[w].vdev.bp)
- DisposPtr(MacRGs[w].vdev.bp);
-
- cgp = (CGrafPtr) MacRGs[w].window; /* unseed window color table */
- (*(*(cgp->portPixMap))->pmTable)->ctSeed = GetCTSeed();
-
- DisposeWindow( MacRGs[w].window); /* Get rid of the actual window */
-
- if (MacRGs[w].palette)
- DisposePalette( MacRGs[w].palette);
-
- MacRGs[w].palette = NULL;
- MacRGs[w].window = NULL;
- sprintf(tempspot,"take away: %d", w); putln(tempspot);
- }
-
- int MacRGfindwind
- (
- WindowPtr wind
- )
- {
- int i=0;
-
- if (!wind)
- return(-2);
-
- while (i<MAX_MAC_RGS && wind != MacRGs[i].window)
- i++;
- if (i==MAX_MAC_RGS)
- return(-1);
-
- return( i);
- }
-
- /************************************************************************************/
- /* MacRGcopy
- * Copybits the image window into the clipboard.
- *
- */
- RGBColor icrwhite = { 0xffff,0xffff,0xffff },
- icrblack = { 0,0,0};
-
- void MacRGcopy
- (
- WindowPtr wind
- )
- {
- Rect copysize,copyfrom;
- long len,wn;
- PicHandle picture;
- CGrafPtr hidep;
-
- if (( wn= MacRGfindwind( wind)) <0)
- return; /* Couldn't do it */
-
- hidep = &MacRGs[wn].vdev.vport;
- copyfrom = MacRGs[wn].vdev.bounds;
-
- SetPort(wind);
-
- copysize = copyfrom; /* boundary of drawing area */
-
- picture= OpenPicture(©size);
-
- ClipRect(©size);
-
- /* RGBBackColor(&icrwhite);
- RGBForeColor(&icrblack); */
-
- ForeColor( blackColor);
- BackColor( whiteColor);
- HLock((Handle) hidep->portPixMap);
-
- CopyBits((BitMap *) (*(hidep->portPixMap)), &wind->portBits,
- ©from, ©size, srcCopy, NULL);
-
- HUnlock((Handle) hidep->portPixMap);
-
- ClosePicture();
-
- /*
- * put the PICT into the scrap manager
- */
- len = GetHandleSize((Handle) picture);
- HLock((Handle) picture);
- ZeroScrap();
- PutScrap( len, 'PICT', (Ptr) *picture);
- HUnlock((Handle) picture);
- KillPicture(picture);
-
- }
-
- int MacRGupdate
- (
- WindowPtr wind
- )
- {
- int wn;
- Rect cbRect;
-
- if (( wn= MacRGfindwind( wind)) <0)
- return(-1); /* Couldn't do it */
-
- SetPort(wind);
- ForeColor( blackColor);
- BackColor( whiteColor);
- BeginUpdate(wind);
- /* EraseRect( &wind->portRect); */
- HLock((Handle) MacRGs[wn].vdev.vport.portPixMap);
- cbRect = MacRGs[wn].vdev.bounds;
- CopyBits((BitMap *) *MacRGs[wn].vdev.vport.portPixMap,&(wind->portBits),
- &cbRect,&cbRect, srcCopy, NULL);
- HUnlock((Handle) MacRGs[wn].vdev.vport.portPixMap);
- EndUpdate( wind);
- return(0);
- }
-
-
- /****************************************
- * MacRGsetdevice() - *
- * Set the RG's to MacWindow stuff *
- ****************************************/
-
- void MacRGsetdevice
- (
- void
- )
- {
- RGbell = MacRGbell;
- RGhidecur = MacRGhidecur;
- RGshowcur = MacRGshowcur;
- RGpencolor = MacRGpencolor;
- RGraster = MacRGraster;
- RGline = MacRGline;
- RGlinestyle = MacRGlinestyle;
- RGpoint = MacRGpoint;
- RGfill = MacRGfill;
- RGcopy = (int (*)()) MacRGcopy;
- RGmap = MacRGmap;
- }
-
- /**************************** Hereafter lie the graphics routines ************************/
-
- MacRGbell( )
- {
- /* Ring bell for wn */
- }
-
- MacRGhidecur( )
- {
- /* hide graphics cursor in wn */
- }
-
- MacRGshowcur( )
- {
- /* show graphics cursor in wn */
- }
-
- MacRGpencolor( r, g, b )
- {
- #pragma unused(r, g, b)
- /* set pen color for wn */
- }
-
- MacRGraster( data, x1,y1,x2,y2, rowbytes)
- char *data;
- int x1,y1,x2,y2,rowbytes;
- {
- Rect tr;
- register char *p;
- register int i;
-
- if (!MacRGs[RGwn].window)
- return(-1);
-
- SetPort( MacRGs[ RGwn].window);
-
- if (MacRGs[RGwn].vdev.bp) { /* If we have off-screen buffer */
-
- p = MacRGs[RGwn].vdev.bp + MacRGs[RGwn].size.h*y1 + x1; /* start point */
- for (i=0; i<rowbytes; i++)
- *p++ = *data++;
-
- SetRect(&tr, x1,y1, x2+1,y2+1);
- InvalRect(&tr);
- }
-
- return(0);
- }
-
- MacRGline( x1,y1,x2,y2)
- {
- #pragma unused(x1, y1, x2, y2)
- /* draw a line in wn */
- }
-
- MacRGlinestyle( style )
- {
- #pragma unused(style)
- /* set the linestyle for wn */
- }
-
- MacRGpoint( x,y )
- {
- #pragma unused(x, y)
- /* set a point in wn */
- }
-
- MacRGfill( x1,y1,x2,y2 )
- {
- #pragma unused(x1, y1, x2, y2)
- /* fill a region in wn */
- }
-
- MacRGcopyrgn( x1,y1,x2,y2, x3,y3,x4,y4 )
- {
- #pragma unused(x1, y1, x2, y2, x3, y3, x4, y4)
- /* copy one region to another within wn */
- }
-
- MacRGmap( start,length,data)
- char *data;
- int start,length;
- {
- int i;
- RGBColor curcol;
-
- for (i=start; i<start+length; i++) {
- curcol.red = (*data++)<<8;
- curcol.green = (*data++)<<8;
- curcol.blue = (*data++)<<8;
- SetEntryColor( MacRGs[RGwn].palette, i, &curcol);
- }
-
- SetPalette( MacRGs[RGwn].window, MacRGs[RGwn].palette, TRUE);
- ActivatePalette( MacRGs[RGwn].window);
-
- ColorVDevice(&MacRGs[RGwn].vdev,MacRGs[RGwn].palette);
-
- sprintf(tempspot, "Palette[%d,%d]",start,length);
- putln(tempspot);
- }
-
-